package com.bbshop.action.product.type;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.bbshop.action.base.BaseAction;
import com.bbshop.bean.common.Pager;
import com.bbshop.bean.common.ProductTypeSearchCondition;
import com.bbshop.bean.common.QueryResult;
import com.bbshop.bean.product.ProductType;
import com.bbshop.service.product.ProductTypeService;
@Controller
public class ProductTypeAction extends BaseAction<ProductType> {

	private static final long serialVersionUID = 1059396124816156756L;

	@Resource
	private ProductTypeService pts;
	private Pager pager;
	private QueryResult<ProductType> qr;
	private ProductType pt;
	private ProductTypeSearchCondition sc;

	public String execute() {
		
		if (pager == null)
			pager = new Pager();
	//	long firstIndex = (pager.getCurrPage() - 1) * pager.getPageSize();
//		setQr(pts.getScrollData(ProductType.class, (int) firstIndex,
//				(int) pager.getPageSize(), null));
		if (sc==null) {
			sc=new ProductTypeSearchCondition();
			sc.setParenttype(null);
		}
		setQr(pts.getScrollData(ProductType.class, pager, sc));
		pager.setTotalRecords(qr.getTotalrecord());
		// pager.setCurrPage(pager.getCurrPage());
		//System.out.println(qr.getResultlist().size());
		//System.out.println(qr.getResultlist().get(0).getSubtypes().size());
		return "success";
	}

	public String add() {
		if (pt.getParenttype() == null
				|| pt.getParenttype().getTypeid() == null) {
			pt.setParenttype(null);
		}
		// System.out.println(pt);
		pts.save(pt);
		return SUCCESS;
	}

	public String addUI() {
		if (pt.getParenttype() == null
				|| pt.getParenttype().getTypeid() == null) {
			pt.setParenttype(null);
		}
		return SUCCESS;
	}

	public String modify() {
		pts.update(pt);
		return SUCCESS;
	}

	public String modifyUI() {
		if (pt.getParenttype() == null
				|| pt.getParenttype().getTypeid() == null) {
			pt.setParenttype(null);
		}
		return SUCCESS;
	}

	public void setPts(ProductTypeService pts) {
		this.pts = pts;
	}

	public ProductTypeService getPts() {
		return pts;
	}

	public void setPager(Pager pager) {
		this.pager = pager;
	}

	public Pager getPager() {
		return pager;
	}

	public void setQr(QueryResult<ProductType> qr) {
		this.qr = qr;
	}

	public QueryResult<ProductType> getQr() {
		return qr;
	}

	public void setPt(ProductType pt) {
		this.pt = pt;
	}

	public ProductType getPt() {
		return pt;
	}

	public ProductTypeSearchCondition getSc() {
		return sc;
	}

	public void setSc(ProductTypeSearchCondition sc) {
		this.sc = sc;
	}
}
